package com.ihr360.payroll.config;

import com.ihr360.commons.lang.DateUtils;
import com.ihr360.commons.model.ITemporalEntity;
import com.ihr360.commons.model.entity.NumberIdWithTime;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SalaryTaxEntity extends NumberIdWithTime<Long> implements ITemporalEntity {

    /**
     * 生效日期
     */
    private Date effectiveAt;

    /**
     * 失效日期
     */
    private Date invalidAt;

    /**
     * 固定税率/超额累进
     */
    private boolean fixed = false;

    /**
     * 税率规则
     */

    private List<SalaryTaxRuleEntity> rules = new ArrayList<>();

    @Override
    public Date getEffectiveAt() {
        return effectiveAt;
    }

    @Override
    public Date getInvalidAt() {
        return invalidAt;
    }

    @Override
    public void setEffectiveAt(Date effectiveAt) {
        this.effectiveAt = effectiveAt;
    }

    @Override
    public void setInvalidAt(Date invalidAt) {
        this.invalidAt = invalidAt;
    }

    public boolean isFixed() {
        return fixed;
    }

    public void setFixed(boolean fixed) {
        this.fixed = fixed;
    }

    public List<SalaryTaxRuleEntity> getRules() {
        return rules;
    }

    public void setRules(List<SalaryTaxRuleEntity> rules) {
        this.rules = rules;
    }

    public boolean isCurrentEffective() {
        Date currentMinDate = DateUtils.getMinDateInDay(new Date());
        Date currentMaxDate = DateUtils.getMaxDateInDay(new Date());
        return this.effectiveAt != null && (this.effectiveAt.before(currentMinDate) || DateUtils.isSameDay(this.effectiveAt, currentMaxDate))
                && (this.invalidAt == null || this.invalidAt.after(currentMaxDate));
    }
}
